#!/bin/bash

set -e
set -x

# wget https://github.com/prometheus/pushgateway/releases/download/v1.11.0/pushgateway-1.11.0.linux-amd64.tar.gz
bypy download pushgateway-1.11.0.linux-amd64.tar.gz
tar xf pushgateway-1.11.0.linux-amd64.tar.gz
mv pushgateway-1.11.0.linux-amd64 /opt/pushgateway
chown -R prometheus:prometheus /opt/pushgateway/
cp pushgateway.service /etc/systemd/system/
systemctl daemon-reload
systemctl enable pushgateway --now
sh ../check_port.sh 9091
time=$(date +'%Y_%m_%d_%H_%M_%S')
sed -i.$time '$r pushgateway.tpl' /opt/prometheus/prometheus.yml
curl -X POST http://localhost:9090/-/reload

# 向pushgateway发送信息
echo "pushgateway_metric 3.14" | curl --data-binary @- http://localhost:9091/metrics/job/pushgateway_job/instance/pushgateway_instance

set +x
set +e